<!--不受理案件弹窗-->
<template>
  <el-dialog append-to-body title="不受理案件" width="45%" :visible="visible" @close="handleClose">
    <el-form ref="form" :model="form" :rules="rules" class="white-card" label-width="140px">
      <el-form-item label="不受理原因：" prop="notAcceptReason">
        <el-select v-model="form.notAcceptReason" placeholder="请选择" style="width: 100%">
          <el-option v-for="item in optionList" :key="item.id" :label="item.name" :value="item.name"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="不受理备注：" prop="comment">
        <el-input v-model="form.comment" show-word-limit maxlength="300" placeholder="请输入详细描述" type="textarea" style="width: 100%; height: 150px"></el-input>
      </el-form-item>
      <el-form-item label="通知书：" prop="rejectAttachments">
        <!-- <div style="display: flex; align-items: center">
          <input @change="handleFileChange" ref="fileInput" id="fileInput" class="vision-hide" type="file" accept=".bmp,.jpg,.jpeg,.png,.tif,.gif,.mov,.avi,.mp4,.wmv,.rmvb,.docx,.pptx,.xlsx,.doc,.ppt,.xls,.pdf,.rar,.zip,.7z" />
          <el-button :loading="uploading" @click="handleUploadFile" type="primary" plain size="mini">上传附件</el-button>
        </div>
        <el-table :data="fileList" size="mini" style="margin-top: 10px">
          <el-table-column prop="fileName" label="附件名称"></el-table-column>
          <el-table-column prop="fileName" label="文件名称"></el-table-column>
          <el-table-column label="操作" width="240px" align="center">
            <template slot-scope="{ row, $index }">
              <el-button @click="handleDownload(row)" type="primary" plain size="mini">下载</el-button>
              <el-button @click="handleRemoveFile($index)" type="primary" plain size="mini">删除</el-button>
            </template>
          </el-table-column>
        </el-table> -->
        <upload-input :file-list="form.rejectAttachments" :tipsText="''"></upload-input>
      </el-form-item>
    </el-form>
    <div class="split"></div>

    <div class="dialog-footer-btn">
      <el-button @click="handleClose" type="primary" plain>关闭</el-button>
      <el-button @click="handleSubmit" :loading="submitting" type="primary">确定</el-button>
    </div>
  </el-dialog>
  <!-- <previewDialog :visible.sync="previewDialog.visible" :filePath="previewDialog.fileURL" width="900px"></previewDialog> -->
</template>

<script>
import previewDialog from "@/views/workOrder/components/previewDialog";
import * as fileApi from "@/api/file";
import * as mixins from "@/utils/mixins";
import * as dictApi from "@/api/dict";
import * as workOrderApi from "@/api/workOrder/index";
import * as templateApi from "@/api/template";
import { fileSize } from "@/utils/common";
import UploadInput from "@/components/uploadInput/uploadInput.vue";
export default {
  name: "notAcceptDialog",
  mixins: [mixins.dialog, mixins.form],
  props: ["visible", "workOrderNo"],
  components: { previewDialog, UploadInput },
  data() {
    return {
      form: {
        notAcceptReason: "",
        comment: "",
        rejectAttachments: "",
      },
      rules: {
        // comment: [{ required: true, message: "请填写" }],
        notAcceptReason: [{ required: true, message: "请选择" }],
        rejectAttachments: [{ required: true, message: "请选择" }],
      },
      optionList: [],
      submitting: false,
      uploading: false,
      fileList: [],
    };
  },
  watch: {
    fileList: {
      deep: true,
      immediate: true,
      handler(val) {
        this.form.rejectAttachments = val;
      },
    },
  },
  methods: {
    handleUploadFile() {
      this.$refs.fileInput.click();
    },
    handleFileChange(e) {
      const file = e.target.files[0];
      if (fileSize(file) > 100) {
        this.clearFileInput();
        return this.$message.error("请上传100M以内的文件");
      }

      const formData = new FormData();
      formData.append("file", file);
      this.uploading = true;
      fileApi
        .upload(formData)
        .then((res) => {
          this.uploading = false;
          this.$message.success("上传成功");
          this.fileList.push({
            fileName: file.name,
            fileUrl: res.data,
          });
        })
        .finally(() => {
          this.clearFileInput();
          this.uploading = false;
          this.$nextTick(postPortalsHeight);
        });
    },
    handleDownload(row) {
      fileApi.download({
        downloadFileName: row.fileName,
        filePath: row.fileUrl,
      });
    },
    handlePreview(row) {
      this.previewDialog = {
        visible: true,
        fileURL: row.fileUrl,
      };
    },
    handleRemoveFile(index) {
      this.fileList.splice(index, 1);
    },
    show() {
      dictApi.list({ parentCode: "1001" }).then((res) => {
        this.optionList = res.result;
      });
      // 不受理备注	1004
      templateApi.detailByCode(1004).then((res) => {
        this.form.comment = res.result.value;
      });
    },
    handleSubmit() {
      this.validateAndConfirm("form")
        .then((res) => {
          this.submitting = true;
          return workOrderApi.distribute.reject({
            ...this.form,
            workOrderNo: this.workOrderNo,
          });
        })
        .then(() => {
          this.$emit("success");
          this.handleClose();
        })
        .finally(() => {
          this.submitting = false;
        });
    },
  },
};
</script>

<style scoped>
.el-select-dropdown .el-select-dropdown__wrap .el-select-dropdown__menu .el-select-dropdown__menu-item {
  white-space: normal; /* 允许文本换行 */
  word-break: break-all; /* 允许在单词内换行 */
  text-overflow: inherit; /* 继承父元素的 text-overflow 属性，如果不希望超出部分隐藏则设为 inherit 或其他值 */
}
</style>
